<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Match Details</title>
        <ui:include src="../header.xhtml"/>
    </h:head>
    <h:body>
        <hr/>
        <h:messages style="color: red"> </h:messages>
        <h:panelGrid columns="1" border="0">
            <f:view>
                <h:form>
                    <h:dataTable value="#{mainPageManagedBean.selectedMatch}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="HomeTeam"/>
                            </f:facet>
                            <h:outputText value="#{item.homeTeam}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="AwayTeam"/>
                            </f:facet>
                            <h:outputText value="#{item.awayTeam}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="AwayTeamScore"/>
                            </f:facet>
                            <h:outputText value="#{item.awayTeamScore}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="HomeTeamScore"/>
                            </f:facet>
                            <h:outputText value="#{item.homeTeamScore}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Court"/>
                            </f:facet>
                            <h:outputText value="#{item.court}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Tournament"/>
                            </f:facet>
                            <h:outputText value="#{item.tournament.name}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="mDate"/>
                            </f:facet>
                            <h:outputText value="#{item.mDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="mTime"/>
                            </f:facet>
                            <h:outputText value="#{item.mTime}"/>
                        </h:column>
                    </h:dataTable>
                </h:form>
            </f:view>
            <h:panelGrid columns="2" border="0">
                <f:view>
                    <h:dataTable value="#{mainPageManagedBean.selectedMatch.statistics}" var="item" border="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                        <f:facet name="header">
                            <h:outputText value="Statistics"/>
                        </f:facet>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Aces"/>
                            </f:facet>
                            <h:outputText value="#{item.aces}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="First Points Won"/>
                            </f:facet>
                            <h:outputText value="#{item.firstSPtsWon}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Second Points Won"/>
                            </f:facet>
                            <h:outputText value="#{item.secondSPtsWon}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Return Points Won"/>
                            </f:facet>
                            <h:outputText value="#{item.returnPtsWon}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Total Points Won"/>
                            </f:facet>
                            <h:outputText value="#{item.totalPtsWon}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Double Fauls"/>
                            </f:facet>
                            <h:outputText value="#{item.doubleFauls}"/>
                        </h:column>
                    </h:dataTable>
                </f:view>
                <f:view>
                    <h:form>
                        <h:dataTable value="#{mainPageManagedBean.selectedMatch}" var="match">
                            <f:facet name="header">
                                <h:outputText value="Select Winner"/>
                            </f:facet>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Home Team"/>
                                    &nbsp;
                                    <h:commandLink value="Select"
                                                   rendered="#{umpireManagedBean.canAssignWinner(mainPageManagedBean.selectedMatch.tournament,mainPageManagedBean.selectedMatch.homeTeam)}"
                                                   action="#{umpireManagedBean.selectWinner(mainPageManagedBean.selectedMatch.homeTeam, mainPageManagedBean.selectedMatch.tournament)}"/>
                                </f:facet>
                                <h:outputText value="#{match.homeTeam}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Away Team"/>
                                    &nbsp;
                                    <h:commandLink value="Select"
                                                   rendered="#{umpireManagedBean.canAssignWinner(mainPageManagedBean.selectedMatch.tournament,mainPageManagedBean.selectedMatch.awayTeam)}"
                                                   action="#{umpireManagedBean.selectWinner(mainPageManagedBean.selectedMatch.awayTeam, mainPageManagedBean.selectedMatch.tournament)}"/>
                                </f:facet>
                                <h:outputText value="#{match.awayTeam}"/>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                </f:view>
                <h:form>
                    <h:commandButton value="Add/Edit Statistics" action="#{umpireManagedBean.linkStatistics(mainPageManagedBean.selectedMatch)}"/>
                </h:form>
            </h:panelGrid>
            <f:view>
                <h:panelGrid columns="2">
                    <h:form>
                        <h:dataTable value="#{mainPageManagedBean.matchSets}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                            <f:facet name="header">
                                <h:outputText value="Sets and Games"/>
                            </f:facet>
                            <h:column>
                                <h:dataTable value="#{item.games}" var="game">
                                    <f:facet name="header">
                                        <center>
                                            <h:outputText value="#{item.homeTeamScore} - #{item.awayTeamScore}"/>&nbsp;
                                            <h:commandLink value="Edit" action="#{setManagedBean.linkSet(item,mainPageManagedBean.selectedMatch)}"/>&nbsp;
                                            <h:commandLink value="Remove" action="#{setManagedBean.removeSet(item,mainPageManagedBean.selectedMatch)}"/>
                                        </center>
                                    </f:facet>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Home Team Score"/>
                                        </f:facet>
                                        <h:outputText value="#{game.homeTeamScore}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Away Team Score"/>
                                        </f:facet>
                                        <h:outputText value="#{game.awayTeamScore}"/>
                                    </h:column>
                                </h:dataTable>
                            </h:column>
                        </h:dataTable>
                        <h:commandButton value="Add New Set" action="#{setManagedBean.linkSet(null,mainPageManagedBean.selectedMatch)}"/>
                    </h:form>
                    <h:panelGrid columns="2">
                        <h:form>
                            <h:dataTable value="#{mainPageManagedBean.matchReferees}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Referees"/>
                                    </f:facet>
                                    <h:outputText value="#{item}"/>
                                </h:column>
                            </h:dataTable>
                        </h:form>
                        <h:form>
                            <h:dataTable value="#{mainPageManagedBean.matchUmpires}" var="item" rowClasses="jsfcrud_odd_row,jsfcrud_even_row">
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Umpires"/>
                                    </f:facet>
                                    <h:outputText value="#{item}"/>
                                </h:column>
                            </h:dataTable>
                        </h:form>
                    </h:panelGrid>
                </h:panelGrid>
            </f:view>
        </h:panelGrid>
    </h:body>
</html>

